﻿/*
* jQuery Mobile Framework : temporary extension to port jQuery UI's datepicker for mobile
* Copyright (c) jQuery Project
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
(function ($, undefined) {

    //cache previous datepicker ui method
    var prevDp = $.fn.datepicker;

    //rewrite datepicker
    $.fn.datepicker = function (options) {

        var dp = this;

        //call cached datepicker plugin
        prevDp.call(this, options);

        //extend with some dom manipulation to update the markup for jQM
        //call immediately
        function updateDatepicker() {
            $(".ui-datepicker-header", dp).addClass("ui-body-c ui-corner-top").removeClass("ui-corner-all");
            $(".ui-datepicker-prev, .ui-datepicker-next", dp).attr("href", "#");
            $(".ui-datepicker-prev", dp).buttonMarkup({ iconpos: "notext", icon: "arrow-l", shadow: true, corners: true });
            $(".ui-datepicker-next", dp).buttonMarkup({ iconpos: "notext", icon: "arrow-r", shadow: true, corners: true });
            $(".ui-datepicker-calendar th", dp).addClass("ui-bar-c");
            $(".ui-datepicker-calendar td", dp).addClass("ui-body-c");
            $(".ui-datepicker-calendar a", dp).buttonMarkup({ corners: false, shadow: false });
            $(".ui-datepicker-calendar a.ui-state-active", dp).addClass("ui-btn-active"); // selected date
            $(".ui-datepicker-calendar a.ui-state-highlight", dp).addClass("ui-btn-up-e"); // today"s date
            $(".ui-datepicker-calendar .ui-btn", dp).each(function () {
                var el = $(this);
                // remove extra button markup - necessary for date value to be interpreted correctly
                el.html(el.find(".ui-btn-text").text());
            });
        };

        //update now
        updateDatepicker();

        // and on click
        $(dp).click(updateDatepicker);

        //return jqm obj 
        return this;
    };
    //bind to pagecreate to automatically enhance date inputs	
    $("#page-Schedule").live("pagecreate", function () {
        $("#schdate2").after($("<div />").datepicker({
                altField: "#schdate2", 
                showOtherMonths: true,
                dateFormat: 'yy-mm-dd' ,
                beforeShowDay: function (date) {
                    var ff = _ChkScheduleDay2(date.getDate());
                    if (ff) {
                        return [true, 'SelectDay'];
                    }
                    else {
                        return [false, ''];
                    }
                },
                onSelect: _ScheduleSelect2,
                onChangeMonthYear: function (year, month, inst) { _GetScheduleMonthList2(year, month); }

                 }));
       });
    
})(jQuery);


    function _ScheduleSelect2(dateText, inst) {
        alert(dateText);
        // SetListview($('#page-Schedule2').find('.ulItemList'), 'ScheduleList', dateText);
    }

    function _ChkScheduleDay2(dd) {
//        if (ScheduleMonth == undefined) return false;
//        var Rows = ScheduleMonth.Records.length;
//        for (var i = 0; i < Rows; i++) {
//            var DataRow = ScheduleMonth.Records[i];
//            if (DataRow.dd == dd) {
//                alert(DataRow.dd + ' / ' + dd);  
//                return true;
//            }
//            if (DataRow.dd > dd) return false;
//        }
        return true;
    }

    function _GetScheduleMonthList2(yy, mm) {
//        ScheduleMonth = undefined;
//        var pl = new JSONClientParameters();
//        pl.add("SvcID", "ScheduleMonthList");
//        var pstr = "<DataTable><Record>";
//        pstr += "<p1>" + yy + "</p1>";
//        pstr += "<p2>" + mm + "</p2>";
//        pstr += "<us>" + sm28 + "</us>";
//        pstr += "</Record></DataTable>";
//        pl.add("XmlParms", pstr);
//        ScheduleMonth = PostJsonSync("/bzService/DBProxy.asmx/execComm", pl);
    }
